package com.yxq.mdt.app.modules.personal.adapter;

import android.graphics.Color;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.modules.personal.bean.RechargeRecordBean;

import java.util.List;

/**
 * @author L
 * @time 2019-11-18
 * @describe 蜜豆记录列表$
 */
public class RechargeHistoryItemListAdapter extends BaseQuickAdapter<RechargeRecordBean.ListBean, BaseViewHolder> {

    public RechargeHistoryItemListAdapter(int layoutResId, @Nullable List<RechargeRecordBean.ListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, RechargeRecordBean.ListBean item) {
        TextView mTextView = helper.getView(R.id.recharge_tv_price);
        if (!TextUtils.isEmpty(item.getUserName())) {
            helper.setText(R.id.recharge_tv_desc, item.getUserName());
        } else if (!TextUtils.isEmpty(item.getTargetUserName())) {
            helper.setText(R.id.recharge_tv_desc, item.getTargetUserName());
        } else {
            helper.setText(R.id.recharge_tv_desc, "");
        }
        helper.setText(R.id.recharge_tv_time, item.getAddTime());

        //类型：1相册打赏；2送礼；3语音聊天；4视频单聊;5:直播送礼;6:充值；7:提现
        switch (item.getType()) {
            case "1":
                helper.setImageResource(R.id.recharge_iv_icon, R.mipmap.icon_personal_reward);
                setContentTextColor(mTextView, "-" + item.getPrice() + "蜜豆", false);
                break;
            case "2":
                helper.setImageResource(R.id.recharge_iv_icon, R.mipmap.icon_personal_gift);
                setContentTextColor(mTextView, "-" + item.getPrice() + "蜜豆", false);
                break;
            case "3":
                helper.setImageResource(R.id.recharge_iv_icon, R.mipmap.icon_personal_telephone);
                setContentTextColor(mTextView, "-" + item.getPrice() + "蜜豆", false);
                break;
            case "4":
                helper.setImageResource(R.id.recharge_iv_icon, R.mipmap.icon_personal_video_icon);
                setContentTextColor(mTextView, "-" + item.getPrice() + "蜜豆", false);
                break;
            case "5":
                helper.setImageResource(R.id.recharge_iv_icon, R.mipmap.icon_personal_gift);
                setContentTextColor(mTextView, "-" + item.getPrice() + "蜜豆", false);
                break;
            case "6":
                helper.setImageResource(R.id.recharge_iv_icon, R.mipmap.icon_personal_recharge);
                if (item.getCashRecharge() != null && item.getCashRecharge().getOrderNo() != null) {
                    if (!TextUtils.isEmpty(item.getUserName())) {
                        helper.setText(R.id.recharge_tv_desc, item.getUserName() + "(" + item.getCashRecharge().getOrderNo() + ")");
                    }
                }
                setContentTextColor(mTextView, "+" + item.getPrice() + "蜜豆", true);
                break;
            case "7":
                helper.setImageResource(R.id.recharge_iv_icon, R.mipmap.icon_personal_reward);
                setContentTextColor(mTextView, "-" + item.getPrice() + "蜜钻", false);
                break;
        }
    }

    private void setContentTextColor(TextView mTextView, String content, boolean b) {
        SpannableStringBuilder spannableBuilder = new SpannableStringBuilder(content);
        // 单独设置字体颜色
        ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor(b ? "#6368FF" : "#FF4E6C"));
        spannableBuilder.setSpan(colorSpan, 0, spannableBuilder.length() - 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        mTextView.setText(spannableBuilder);
    }

}
